<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - Bootstrap Table</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="/admin/favicon.ico"> 
    <link href="/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">

    <!-- <link href="/admin/css/plugins/iCheck/custom.css" rel="stylesheet"> -->

    <!-- <link href="/admin/css/plugins/chosen/chosen.css" rel="stylesheet"> -->

    <!-- <link href="/admin/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet"> -->

    <!-- <link href="/admin/css/plugins/cropper/cropper.min.css" rel="stylesheet"> -->

    <!-- <link href="/admin/css/plugins/switchery/switchery.css" rel="stylesheet"> -->

    <!-- <link href="/admin/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet"> -->

    <!-- <link href="/admin/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet"> -->

    <!-- <link href="/admin/css/plugins/datapicker/datepicker3.css" rel="stylesheet"> -->

    <!-- <link href="/admin/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet"> -->
    <!-- <link href="/admin/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet"> -->

    <link href="/admin/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">

    <!-- <link href="/admin/css/plugins/clockpicker/clockpicker.css" rel="stylesheet"> -->

    <link href="/admin/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="/admin/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">

    <link href="/admin/css/animate.css" rel="stylesheet">
    <link href="/admin/css/style.css?v=4.1.0" rel="stylesheet">
    

</head>

<body class="">
    <div class="wrapper wrapper-content animated fadeInRight">
        <!-- <div class="ibox-content"> -->
            <!-- <div class="row row-lg"> -->
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content" style="border:0">
                            <form action="/admin/goods/goods_insert" method="post" class="form-horizontal m-t" enctype="multipart/form-data" id="signupForm" onsubmit="return false">
                                <input type="hidden" name='id' value="{{$piece->id}}">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">所属分类：</label>
                                    <div class="col-sm-8">
                                        <select class="form-control" name="type">
                                        @foreach($arr as $list)
                                            <option value="{{$list->id}}">
                                            @php
                                            substr_count($list->type,',');
                                            echo str_repeat('——',substr_count($list->type,',')-1);
                                            @endphp
                                            {{$list->classify}}</option>       
                                        @endforeach
                                        </select>

                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">商品名：</label>
                                    <div class="col-sm-8">
                                        <input id="name" name="name" class="form-control" type="text" value="{{$piece->name}}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">图片：</label>
                                    <div class="col-sm-8">
                                        <input type="file" class="form-control" id='img' name='img'>
                                        <img src="/upload/{{$piece->img}}" width="100" id="preview" alt="">
                                    </div>
                                    {{--<!-- <div class="col-sm-8">
                                        <div class="page-container">
                                            <p>您可以尝试文件拖拽，使用QQ截屏工具，然后激活窗口后粘贴，或者点击添加图片按钮，来体验此demo.</p>
                                            <div id="uploader" class="wu-example">
                                                <div class="queueList">
                                                    <div id="dndArea" class="placeholder">
                                                        <div id="filePicker"></div>
                                                        <p>或将照片拖到这里，单次最多可选300张</p>
                                                    </div>
                                                </div>
                                                <div class="statusBar" style="display:none;">
                                                    <div class="progress">
                                                        <span class="text">0%</span>
                                                        <span class="percentage"></span>
                                                    </div>
                                                    <div class="info"></div>
                                                    <div class="btns">
                                                        <div id="filePicker2"></div>
                                                        <div class="uploadBtn">开始上传</div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div> -->--}}
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">价格：</label>
                                    <div class="col-sm-8">
                                        <input id="price" name="price" class="form-control" type="text" value="{{$piece->price}}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-3 control-label">关键字：</label>
                                    <div class="col-sm-8">
                                        <input id="keywords" name="keywords" class="form-control" type="text" value="{{$piece->keywords}}">
                                    </div>
                                </div>
                                 <div class="form-group">
                                    <label class="col-sm-3 control-label">详情：</label>
                                    <div class="col-sm-8">
                                        <div class="ibox float-e-margins">
                                            <div class="ibox-title" style="border:1px solid #e5e6e7;">
                                                <h5>编辑/保存为html代码示例</h5>
                                                <button id="edit" class="btn btn-primary btn-xs m-l-sm" type="button">编辑</button>
                                                <button id="save" class="btn btn-primary  btn-xs" type="button">保存</button>
                                            </div>
                                            <div class="ibox-content" id="eg">

                                                <div id='details' class="click2edit wrapper">
                                                    {{$piece->details}}
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-sm-8 col-sm-offset-3">
                                        <button class="btn btn-primary" id="update" type="submit">提交</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            <!-- </div> -->
        <!-- </div> -->
    </div>



    <!-- 全局js -->
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="/admin/js/layer.js"></script>

    <!-- 自定义js -->
    <script src="/admin/js/content.js?v=1.0.0"></script>

    <!-- SUMMERNOTE -->
    <script src="/admin/js/plugins/summernote/summernote.min.js"></script>
    <script src="/admin/js/plugins/summernote/summernote-zh-CN.js"></script>

    <!-- Bootstrap table -->
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <!-- jQuery Validation plugin javascript-->
    <script src="/admin/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="/admin/js/plugins/validate/messages_zh.min.js"></script>

    <script src="/admin/js/demo/form-validate-demo.js"></script>

    <!-- Peity -->
    <script src="/admin/js/demo/bootstrap-table-demo.js"></script>

    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
    <!--统计代码，可删除-->

    <script>
        // 选中商品原分类
        $("select[name='type'] option").each(function(i){
            if($(this).attr('value')=={{$piece->type}}){
                $(this).prop('selected',true);
            }
        })
    </script>


    <script>
        // 更新
        $('#update').click(function(){
            var formdata=new FormData($('#signupForm')[0]);
            // 过滤掉未修改的字段
               formdata.append('details',$('#details').html());
            if(!$('#img').val()){
               formdata.delete('img');
            }
            var index = parent.layer.getFrameIndex(window.name); //获取当前iframe层索引
            $.ajax({
                url:'/admin/goods/goods_update',
                type:'POST',
                cache:false,
                data:formdata,
                processData: false,
                contentType: false,
                success:function(data){
                    console.log(data);
                    // return;
                    // window.parent.location.reload();
                    if(data==1){
                        // id=$('#id').val(); // 获取表单信息
                        // type=$('#type').val();
                        // name=$('#name').val();
                        // img=$('#img').val();  // 
                        // details=$('#details').html();
                        layer.msg('修改成功',{'icon':1});
                        // parent.$('#table').bootstrapTable('updateRow',{index:index,row:{'type':type,'name':name,'img':img,'details':details}}); //更新父页面bt表格的数据
                    }else{
                        layer.msg('修改失败',{'icon':2});
                    }
                    setTimeout(function(){
                        parent.layer.close(index); //关闭当前iframe层
                    },1000);
                }
            }).done(function(data){
                    // console.log(data);
                window.parent.location.reload();
            }).fail(function(data){
                    console.log(data);
                layer.msg('请正确填写信息',{'icon':2});
            })
        })
    </script>

    <!-- 预显示图片 -->
    <script>
        document.querySelector('#img').addEventListener('change', function(){
            //当没选中图片时，清除预览
            if(this.files.length === 0){
                document.querySelector('#preview').src = '';
                return;
            }
            
            //实例化一个FileReader
            var reader = new FileReader();

            reader.onload = function (e) {
                //当reader加载时，把图片的内容赋值给
                document.querySelector('#preview').src = e.target.result;
            };

            //读取选中的图片，并转换成dataURL格式
            reader.readAsDataURL(this.files[0]);
        }, false);
    </script>

    <!-- 富文本编辑器js -->
    <script>
        $(document).ready(function () {

            $('.summernote').summernote({
                lang: 'zh-CN'
            });

        });
        $('#edit').click(function(){
            $("#eg").addClass("no-padding");
            $('.click2edit').summernote({
                lang: 'zh-CN',
                focus: true
            });
        })
        $('#save').click(function(){
            $("#eg").removeClass("no-padding");
            var aHTML = $('.click2edit').code(); //save HTML If you need(aHTML: array).
            $('.click2edit').destroy();
        })
    </script>

</body>

</html>
